<template>
  <div class="head-container">
    <!-- 搜索 -->
       <el-select v-model="query.typeid" placeholder="巡检类型" v-on:change="indexSelect($event)">
           <el-option v-for="(item,index) in inspectionType" :key="index" :label="item.name" :value="item.value">
           </el-option>
      </el-select>
    <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
    <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
      <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
    </el-select>
    <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
    <!-- 新增 -->
    <div style="display: inline-block;margin: 0px 2px;">
      <el-button
        v-permission="['ADMIN','INSPECTIONPLAN_ALL','INSPECTIONPLAN_CREATE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        @click="$refs.form.dialog = true">新增</el-button>
      <eForm ref="form" :is-add="true"/>
    </div>
  </div>
</template>

<script>
import eForm from './form'
import request from '@/utils/request'
export default {
  components: { eForm },
  props: {
    query: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
    inspectionType:[{
          value:1,
          name:'设备类巡检'
      },{
          value:2,
          name:'设施类巡检',
      },{
          value:3,
          name:'管理类巡检'
      }],
     
      queryTypeOptions: [
        { key: 'planName', display_name: '计划名称' },
        { key: 'toolName', display_name: '巡检工具名称' },
        { key: 'periodName', display_name: '巡检周期名称' },
        { key: 'inspectorName', display_name: '巡检人名称' },
        { key: 'vehtypeName', display_name: '巡检车辆类型m名称' }
      ]
    }
  },
  methods: {
     byNameinfo(name) {
      this.byName(name).then(res => {
        if(res.id!=null){
            this.bydictId(res.id).then(resobject => {
              const _this = this.$refs.form
              debugger;
              _this.inspectionObject=resobject;
            //根据id再进行全部查询
          })
        }

        //根据id再进行全部查询
      })
    },
    indexSelect(event){
        debugger;
    　　//console.log(event.target.label);//在这里可以正确输出每个下拉框对应的下标值，当然输出值都是可以的
        if(event==1){
            this.byNameinfo("设备类巡检");
        }else if(event==2){
            this.byNameinfo("设施类巡检");
        }else if(event==3){
            this.byNameinfo("管理类巡检");
        }
    },
        // 获取id值
    byName(name) {
      return request({
        url: 'api/dict/byName/' + name,
        method: 'get'
      })
    },
            // 获取id值
    bydictId(id) {
      return request({
        url: 'api/dictDetail/findByDeptId/' + id,
        method: 'get'
      })
    },
    toQuery() {
      this.$parent.page = 0
      this.$parent.init()
    }
  }
}
</script>
